﻿@using PagedList.Mvc;
@using PagedList;
@using TestOnlineProject.Models.Entities
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@{
    if (!String.IsNullOrEmpty(ViewBag.Msg))
    {
    <script>        alert("@ViewBag.Msg")</script>
    }
}
<script>
    // Select created by
    $(document).ready(function () {
        var values = $(".created_by").val();
        if (values == "actualUser") {
            $(".actual_user").css("display", "inline");
        }
        else {
            $(".actual_user").css("display", "none");
        }

        $(".created_by").change(function () {
            var values = $(this).val();
            if (values == "actualUser") {
                $(".actual_user").css("display", "inline");
            }
            else {
                $(".actual_user").css("display", "none");
            }

            // Clear actual people.
            $("#actualUser").val("");
            $("#actual_user").val("");
        });
    });

    // Autpcomplete user.
    $(function () {
        $("#actual_user").autocomplete({
            source: "Question/AutocompleteUser",
            minLength: 1,
            select: function (event, ui) {
                if (ui.item) {
                    $("#actual_user").val(ui.item.value);
                    $("#actualUser").val(ui.item.id);
                }
            }
        });
    });

</script>
<div class="site_map">
    @Html.ActionLink("Home", "Index", "Home") / @Html.ActionLink("Subjects", "Index", "Subject", new { id = (ViewBag.Subject as Subject).SubjectId }, null)
    / @Html.ActionLink((ViewBag.Subject as Subject).Code, "Details", "Subject", new { id = (ViewBag.Subject as Subject).SubjectId }, null)
    / Sections</div>
<br />
<div class="main_nav">
    <span><a href="@Url.Content("~/Subject/Details")?id=@ViewBag.Subject.SubjectId">
        <img src="@Url.Content("~/Images/back button.png")" style="height:30px"/></a>
    </span><span style="float: right">
        @if (HttpContext.Current.User.IsInRole("1"))
        {
            @Html.ActionLink("Participants", "Index", "Participant", new { subjectId = ViewBag.Subject.SubjectId }, new { })
            <span>|</span>
        }
        @Html.ActionLink("Questions", "Index", "Question", new { subjectId = ViewBag.Subject.SubjectId }, new { })
        |
        @Html.ActionLink("Tests", "Index", "Test", new { subjectId = ViewBag.Subject.SubjectId }, new { })
        |
        @Html.ActionLink("Discussions", "Index", "Discussion", new { subjectId = ViewBag.Subject.SubjectId }, new { })
    </span>
</div>
<br />
<div class="search_content">
    @using (Ajax.BeginForm("Index", "Section", new AjaxOptions
{
    InsertionMode = InsertionMode.Replace,
    HttpMethod = "GET",
    UpdateTargetId = "unobtrusive",
}, new
{
    @class
    = "form-inline"
}))
    {
        <input type="hidden" name="subjectId" value="@ViewBag.SubjectId"/>
        @Html.DropDownList("createdBy", @ViewBag.CreatedByList as SelectList, "Creator", new { @class = "created_by" })
        <input type="hidden" name="actualUser" id="actualUser" />
        <input type="text" name="keyWord" placeholder="Section's Title" />
       
        <button type="submit" class="btn" value="Search" style="width: 80px">
            Search</button>
        @Html.ActionLink("Reload", "Index", "Section", new { subjectId = @ViewBag.SubjectId }, new { @class = "btn", style = "width:54px" })
        <br />
        <input id="actual_user" type="text" class="actual_user" style="display: none; margin-top: 5px"
            placeholder="Full Name or Username" />
    }
</div>
<br />
<div>
    @*<span>@Html.ActionLink("Create Question", "Create", "Question", new { subjectId = @ViewBag.SubjectId }, new { @class = "btn" })</span>*@
    <span>@Html.ActionLink("Create Section", "Create", new { subjectId = @ViewBag.SubjectId }, new { @class = "btn" })</span>
    @*<span>@Html.ActionLink("Default Section", "Index", "Question", new { subjectId = @ViewBag.SubjectId }, new { @class = "btn" })</span>*@
</div>
<br />
<div id="unobtrusive">
    @Html.Partial("_List")
</div>
